
#pragma once

#ifdef _USRDLL
#define DllExport   __declspec( dllexport )
//#else
//#define DllExport	__declspec( dllimport )
#else
#define DllExport
#endif

struct IM_MP4_DEC;

class CIBuffer
{
	// if succeed, S_OK, else E_FAIL
public:
	virtual HRESULT CreateObj( void ) = 0;									// can create the object, 
	virtual HRESULT Read(void * buf, size_t bufSize, size_t *readed ) = 0;	// read given size bytes to buffer
																			// if no more data, return S_FALSE
																			// else if succeed, return S_OK,  and set the readed 
	virtual HRESULT Rewind() = 0;											// rewind to begin of bitstream
	virtual HRESULT	Release(void) = 0;										// release obj, can safely delete
};

struct PicInfo
{
	BYTE *Y;				/** Pointer to the Y-plane data, of size Width x Height, with stride BpS */
	BYTE *U;				/** Pointer to the U-plane data, of size Width/2 x Height/2, with stride BpS */
	BYTE *V;				/** Pointer to the V plane data, of size Width/2 x Height/2, with stride BpS */

	int Width;				/** Width of picture, in pixel. */
	int Height;				/** Height of picture, in pixel. */
	int BpS;				/** Bytes Per Scanline */
	double Time;			/** Presentation time, in seconds */
	unsigned __int64 Time_Ticks; /** Presentation time, in ticks */
	int BitRead;

	unsigned char	*pHeader;
	int				nHeaderSize;

	int VOP_Coding_Type;	/**< Coding type. Set by the decoder. Values: 0:key frame (I-VOP), 1:P-VOP, 2:B-VOP, 3:S/D-VOP, 4: not coded */
};

struct SWM
{
	int wx;
	int wy;
	int *pwm;
};

struct SMDInfo
{
	int mdbw;
	int mdbh;
	int mcount;	// motion count
	char *pmmy;	// motion map
};

#define MP4SETCODE_WMEN				0
#define MP4SETCODE_WMBIT			1
#define MP4SETCODE_MDEN				2
#define MP4SETCODE_MDSENTIVITY		3
#define MP4SETCODE_MDCOMPLEXITY		4
#define MP4SETCODE_MDEROSION		5
#define MP4SETCODE_MDDILATION		6
#define MP4SETCODE_SKIPERRORSTREAM	7

#define MP4GETCODE_WATERMARK		0
#define MP4GETCODE_MOTIONDECTION	1

#ifdef __cplusplus
extern "C" 
{
#endif
typedef void* MP4HANDLE;

DllExport MP4HANDLE MP4DecodeInitialIH(CIBuffer* pcibuffer );
DllExport const PicInfo* MP4DecodeOneFrameIH(MP4HANDLE handle);
DllExport void MP4DecodeFinishIH(MP4HANDLE handle);
DllExport void MP4DecodeRestartIH(MP4HANDLE handle);
DllExport HRESULT MP4DecodeGetInfoIH(MP4HANDLE handle, int &width, int &height);
DllExport const PicInfo* MP4DecodeGetPicInfoIH(MP4HANDLE handle);
DllExport HRESULT MP4DecodeSetParamIH(MP4HANDLE handle, int code, const void* pparam);
DllExport HRESULT MP4DecodeGetParamIH(MP4HANDLE handle, int code, void** pparam);

#ifdef __cplusplus
}
#endif



